package com.aliyun.heiyu.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailUtil {
    private static Logger logger = LoggerFactory.getLogger(EmailUtil.class);

    //邮件服务器主机地址
    private static String HOST="smtp.alibaba.com";
    //帐号
    private static String ACCOUNT = "guodongzhu@163.com";
    //密码

    /**
     * @param toUser  发送邮件给谁
     * @param title   邮件的标题
     * @param emailMsg  邮件信息
     */
    public static void sendMail(String toUser,String title, String emailMsg){
        logger.info("在{} 给{} 发了邮件 标题为{}  信息为{}",new Date(),LogUtils.vaildlog(toUser),LogUtils.vaildlog(title),LogUtils.vaildlog(emailMsg));

    }

    /**
     * 验证邮件格式
     * @param email
     * @return
     */
    public static Boolean verificationEmail(String email){
        if (null==email || "".equals(email)){
            return false;
        }
        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p = Pattern.compile(regEx1);
        Matcher m = p.matcher(email);
        if(m.matches()){
            return true;
        }else{
            return false;
        }
    }
}
